﻿using NetworkPower.Common;
using NetworkPower.DataModel.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace NetworkPower.UI
{
    /// <summary>
    /// Interaction logic for ExportList.xaml
    /// </summary>
    public partial class ExportList : Window
    {
        static NetworkPowerContext context = new NetworkPowerContext();
        private Dictionary<Guid, string> LineProtectBoxs = new Dictionary<Guid, string>();
        private Dictionary<Guid, string> Departments = new Dictionary<Guid, string>();
        bool canSelectLineProtectBox = false;
      
        public ExportList()
        {
            InitializeComponent();
            LoadData();
            InitialLineProtectBox();
        }

        private void LoadData()
        {
            //context.Set<LineProtectBox>().ToList().ForEach(s => LineProtectBoxs.Add(s.LineProtectBoxId, s.LineProtectBoxName));
        }

        private void InitialLineProtectBox()
        {
            canSelectLineProtectBox = false;
            cmbLineProtectBox.ItemsSource = LineProtectBoxs;
            canSelectLineProtectBox = true;
            if (cmbLineProtectBox.Items.Count > 0)
            {
                cmbLineProtectBox.SelectedIndex = 0;
            }
        }

        private void InitialDepartmentSource(string lineProtectBoxId)
        {
            //Departments.Clear();
            //context.Set<Department>().ToList().Where(s => s.LineProtectBoxId.ToString() == lineProtectBoxId).ToList().ForEach(se => Departments.Add(se.DepartmentId, se.DepartmentName));
            //canSelectDepartment = false;
            //cmdDepartment.ItemsSource = Departments;
            //canSelectDepartment = true;
        }

        private void cmdDepartment_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //if (canSelectDepartment)
            //{
            //    var para = ((KeyValuePair<Guid, string>)cmdDepartment.SelectedValue).Key;
            //    var datasource = context.Set<LoopLine>().ToList().Where(s => s.DepartmentId.ToString() == para.ToString()).OrderBy(o => o.RowIndex).ToList();
            //    dataGridView1.ItemsSource = datasource;
            //}
        }

        private void cmbLineProtectBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (canSelectLineProtectBox)
            {
                //var condition = ((KeyValuePair<Guid, string>)cmbLineProtectBox.SelectedValue).Key;
                //var datasource = context.Set<LoopLine>().ToList().Where(s => s.LineProtextId.ToString() == condition.ToString()).OrderBy(o => o.RowIndex).ToList();
                ////dataGridView1.Items.Clear();
                //dataGridView1.ItemsSource = datasource;

                //InitialDepartmentSource(((KeyValuePair<Guid, string>)cmbLineProtectBox.SelectedValue).Key.ToString());
            }
        }
    }

    //public class LoopLineNameColorConverter : IValueConverter
    //{
    //    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    //    {
    //        if (value is LoopLine)
    //        {
    //            short quantity = ((LoopLine)value).LoopLineNameColor;
    //            return ColorMapping.GetColor(quantity);
    //        }
    //        return Brushes.White;
    //    }

    //    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    //    {
    //        throw new NotImplementedException();
    //    }
    //}

    //public class TerminalNoColorConverter : IValueConverter
    //{
    //    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    //    {
    //        if (value is LoopLine)
    //        {
    //            short quantity = ((LoopLine)value).TerminalNoColor;
    //            return ColorMapping.GetColor(quantity);
    //        }
    //        return Brushes.White;
    //    }

    //    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    //    {
    //        throw new NotImplementedException();
    //    }
    //}
}
